|
|
@@ -3,10 +3,10 @@ require 'rails_helper'
|
3
|
3
|
describe Agents::TwitterUserAgent do
|
4
|
4
|
before do
|
5
|
5
|
# intercept the twitter API request for @tectonic's user profile
|
6
|
|
- stub_request(:any, "https://api.twitter.com/1.1/statuses/home_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
|
|
6
|
+ stub_request(:any, "https://api.twitter.com/1.1/statuses/user_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true&screen_name=tectonic").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
|
7
|
7
|
|
8
|
8
|
@opts = {
|
9
|
|
- #:username => "tectonic",
|
|
9
|
+ :username => "tectonic",
|
10
|
10
|
:include_retweets => "true",
|
11
|
11
|
:exclude_replies => "false",
|
12
|
12
|
:expected_update_period_in_days => "2",
|
|
|
@@ -14,8 +14,7 @@ describe Agents::TwitterUserAgent do
|
14
|
14
|
:consumer_key => "---",
|
15
|
15
|
:consumer_secret => "---",
|
16
|
16
|
:oauth_token => "---",
|
17
|
|
- :oauth_token_secret => "---",
|
18
|
|
- :choose_home_time_line => 'true'
|
|
17
|
+ :oauth_token_secret => "---"
|
19
|
18
|
}
|
20
|
19
|
|
21
|
20
|
@checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => @opts)
|
|
|
@@ -45,12 +44,30 @@ describe Agents::TwitterUserAgent do
|
45
|
44
|
|
46
|
45
|
describe "#check that if choose time line is false then username is required" do
|
47
|
46
|
before do
|
48
|
|
- stub_request(:any, "https://api.twitter.com/1.1/statuses/user_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
|
|
47
|
+ stub_request(:any, "https://api.twitter.com/1.1/statuses/home_timeline.json?contributor_details=true&count=200&exclude_replies=false&include_entities=true&include_rts=true").to_return(:body => File.read(Rails.root.join("spec/data_fixtures/user_tweets.json")), :status => 200)
|
49
|
48
|
end
|
50
|
49
|
|
51
|
|
- it "should check that error messaged added if choose time line is false" do
|
52
|
|
-
|
53
|
|
- opts = @opts.merge!({:choose_home_time_line => "false" })
|
|
50
|
+ it 'requires username unless choose_home_time_line is true' do
|
|
51
|
+ expect(@checker).to be_valid
|
|
52
|
+
|
|
53
|
+ @checker.options['username'] = nil
|
|
54
|
+ expect(@checker).to_not be_valid
|
|
55
|
+
|
|
56
|
+ @checker.options['choose_home_time_line'] = 'true'
|
|
57
|
+ expect(@checker).to be_valid
|
|
58
|
+ end
|
|
59
|
+
|
|
60
|
+ context "when choose_home_time_line is true" do
|
|
61
|
+ before do
|
|
62
|
+ @checker.options['choose_home_time_line'] = true
|
|
63
|
+ @checker.options.delete('username')
|
|
64
|
+ @checker.save!
|
|
65
|
+ end
|
|
66
|
+ end
|
|
67
|
+
|
|
68
|
+ it "error messaged added if choose_home_time_line is false and username does not exist" do
|
|
69
|
+
|
|
70
|
+ opts = @opts.tap { |o| o.delete(:username) }.merge!({:choose_home_time_line => "false" })
|
54
|
71
|
|
55
|
72
|
checker = Agents::TwitterUserAgent.new(:name => "tectonic", :options => opts)
|
56
|
73
|
checker.service = services(:generic)
|